package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.SystemInform;
import cn.wolfcode.trip.base.query.SystemInformQueryObject;
import cn.wolfcode.trip.base.service.ISystemInformService;
import cn.wolfcode.trip.base.util.JasonResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

//系统通知业务控制器
@Controller
@RequestMapping("/systemInform")
public class SystemInformController {
    @Autowired
    private ISystemInformService systemInformService;

    /**
     * 回显列表
     * @param qo
     * @return
     */
    @RequestMapping("/list")
    public Object list(@ModelAttribute("qo") SystemInformQueryObject qo, Model model){
        qo.setOrderBy("releaseTime desc");
        model.addAttribute("pageInfo",systemInformService.selectForList(qo));
        return "systemInform/list";
    }

    /**
     * 发布方法
     * @param systemInform
     */
    @RequestMapping("/release")
    @ResponseBody
    public Object release(SystemInform systemInform){
        JasonResult jasonResult = new JasonResult();

        try {
            systemInformService.save(systemInform);
        } catch (Exception e) {
            e.printStackTrace();
            jasonResult.setMsg(e.getMessage());
        }
        return jasonResult;
    }

}
